import Vue from "vue";
import VueI18n from 'vue-i18n'
import * as cache from "../common/cache";
import moment from 'moment'
Vue.use(VueI18n)
// elementuiui语言包
import locale from 'element-ui/lib/locale'
import localeEN from '@/../node_modules/element-ui/lib/locale/lang/en'
import localeCN from '@/../node_modules/element-ui/lib/locale/lang/zh-CN'
import localeVI from '@/../node_modules/element-ui/lib/locale/lang/vi'

// moment语言包
import momentEN from '@/../node_modules/moment/locale/en-gb'
import momentCN from '@/../node_modules/moment/locale/zh-cn'
import momentVI from '@/../node_modules/moment/locale/vi'


const message = {
    VI: {
        ...localeVI,
        ...momentVI,
        ...require('../i18n/lang/vi')
    },
    CN: {
        ...localeCN,
        ...momentCN,
        ...require('../i18n/lang/zh')
    },
    EN: {
        ...localeEN,
        ...momentEN,
        ...require('../i18n/lang/en')
    },
}

const i18n = new VueI18n({
    // locale: 'Chinese', // 语言标识
    locale: cache.getLang() || 'VI', // 语言标识
    //this.$i18n.locale // 通过切换locale的值来实现语言切换
    messages: message
})
// 加载语言包
locale.i18n((key, value) => i18n.t(key, value))
// 加载时间控件的语言包
Object.keys(message).forEach(key => moment.locale(key, message[key]))
// 设置本地时区
// moment.locale('en')
// Vue.prototype.$i18n = i18n.t('m')

export default i18n